package com.kermel.common.util;

import java.util.Calendar;
import java.util.Date;

import android.test.AndroidTestCase;

public class DateTimeUtilsTest extends AndroidTestCase {
    public static final int AMOUNT_OF_TIME_TO_ADD = 10 * 1000;
    public static final int NEGATIVE_AMOUNT_OF_TIME_TO_ADD = -1 * 1000;
    
    public void testThatTimeInMillisecondsAsDateStringFull_XXXX() {
        long timeInMilliseconds = Calendar.getInstance().getTimeInMillis();
        String result = DateTimeUtils.timeInMillisecondsToDateStringFull(timeInMilliseconds);
        assertNotNull(result);
        assertTrue(result.length() > 0);
    }
    
    public void testRightNowMillisecondsReturnsValueGreaterThanZero() {
        long rightNowInMilliseconds = DateTimeUtils.rightNowInMilliseconds();
        assertTrue(rightNowInMilliseconds > 0);
    }
    
    public void testThatConvertTimeInMillisecondsToDateReturnsNonNullWhenPassedValueLessThanZero() {
        long timeInMilliseconds = -1;
        Date date = DateTimeUtils.timeInMillisecondsToDate(timeInMilliseconds);
        assertNotNull(date);
    }
    
    public void testThatConvertTimeInMillisecondsToDateReturnsNonNullWhenPassedValueEqualToZero() {
        long timeInMilliseconds = 0;
        Date date = DateTimeUtils.timeInMillisecondsToDate(timeInMilliseconds);
        assertNotNull(date);
    }
    
    public void testThatConvertTimeInMillisecondsToDateReturnsNonNullWhenPassedValueGreaterThanZero() {
        long timeInMilliseconds = 1;
        Date date = DateTimeUtils.timeInMillisecondsToDate(timeInMilliseconds);
        assertNotNull(date);
    }
    
    public void testThatAdjustTimeAddsIfAmountOfTimeIsPositive() {
        long timeInMilliseconds = DateTimeUtils.rightNowInMilliseconds();
        int millisecondsToAdd = AMOUNT_OF_TIME_TO_ADD;
        
        long adjustedTimeMillis = DateTimeUtils.adjustDateTime(timeInMilliseconds, millisecondsToAdd);
        
        long delta = adjustedTimeMillis - timeInMilliseconds;
        
        assertEquals(millisecondsToAdd, delta);
    }
    
    public void testThatAdjustTimeSubtractsIfAmountOfTimeIsNegative() {
        long timeInMilliseconds = DateTimeUtils.rightNowInMilliseconds();
        int millisecondsToAdd = NEGATIVE_AMOUNT_OF_TIME_TO_ADD;
        
        long adjustedTimeMillis = DateTimeUtils.adjustDateTime(timeInMilliseconds, millisecondsToAdd);
        
        long delta = adjustedTimeMillis - timeInMilliseconds;
        
        assertEquals(millisecondsToAdd, delta);
    }
    
    public void testThatSecondsToMillisecondsReturnsCorrectValue() {
        long seconds = 1;
        long milliseconds = DateTimeUtils.secondsToMilliseconds(seconds);

        long expected = seconds * DateTimeUtils.MILLISECONDS_PER_SECOND;
        
        assertEquals(expected, milliseconds);
    }
    
    public void testThatMinutesToSecondsReturnsCorrectValue() {
        long minutes = 1;
        long seconds = DateTimeUtils.minutesToSeconds(minutes);
        
        long expected = minutes * DateTimeUtils.SECONDS_PER_MINUTE;
        
        assertEquals(expected, seconds);
    }
    
    public void testThatMinutesToMillisecondsReturnsCorrectValue() {
        long minutes = 1;
        long milliseconds = DateTimeUtils.minutesToMilliseconds(minutes);
        
        long expected = minutes * DateTimeUtils.MILLISECONDS_PER_MINUTE;
        
        assertEquals(expected, milliseconds);
    }
    
    public void testThatHoursToMinutesReturnsCorrectValue() {
        long hours = 1;
        long minutes = DateTimeUtils.hoursToMinutes(hours);
        
        long expected = hours * DateTimeUtils.MINUTES_PER_HOUR;
        
        assertEquals(expected, minutes);
    }
    
    public void testThatHoursToSecondsReturnsCorrectValue() {
        long hours = 1;
        long seconds = DateTimeUtils.hoursToSeconds(hours);
        
        long expected = hours * DateTimeUtils.SECONDS_PER_HOUR;
        
        assertEquals(expected, seconds);
    }
    
    public void testThatHoursToMillisecondsReturnsCorrectValue() {
        long hours = 1;
        long milliseconds = DateTimeUtils.hoursToMilliseconds(hours);
        
        long expected = hours * DateTimeUtils.MILLISECONDS_PER_HOUR;
        
        assertEquals(expected, milliseconds);
    }
    
    public void testThatDaysToHoursReturnsCorrectValue() {
        long days = 1;
        long hours = DateTimeUtils.daysToHours(days);
        
        long expected = days * DateTimeUtils.HOURS_PER_DAY;
        
        assertEquals(expected, hours);
    }
    
    public void testThatDaysToMinutesReturnsCorrectValue() {
        long days = 1;
        long minutes = DateTimeUtils.daysToMinutes(days);
        
        long expected = days * DateTimeUtils.MINUTES_PER_DAY;
        
        assertEquals(expected, minutes);
    }
    
    public void testThatDaysToSecondsReturnsCorrectValue() {
        long days = 1;
        long seconds = DateTimeUtils.daysToSeconds(days);
        
        long expected = days * DateTimeUtils.SECONDS_PER_DAY;
        
        assertEquals(expected, seconds);
    }
    
    public void testThatDaysToMilliscondsReturnsCorrectValue() {
        long days = 1;
        long milliseconds = DateTimeUtils.daysToMilliseconds(days);
        
        long expected = days * DateTimeUtils.MILLISECONDS_PER_DAY;
        
        assertEquals(expected, milliseconds);
    }
    
    public void testThatCreateCalendar() {
        long timeInMilliseconds = 0;
        Calendar dateTime = DateTimeUtils.createCalendar(timeInMilliseconds);
        assertNotNull(dateTime);
    }
}
